package com.hzqc.wxaapp.sdk;

import org.springframework.http.ResponseEntity;
import org.springframework.web.util.UriComponentsBuilder;

import java.net.URI;

/**
 * The type Wechat app url link service.
 */
public class WechatAppUrlLinkService extends AbstractWechatAppService {

    private static final String ENDPOINT = "https://api.weixin.qq.com/wxa/generate_urllink";

    /**
     * Instantiates a new Wechat app url link service.
     *
     * @param wechatAppTokenService the wechat app token service
     */
    public WechatAppUrlLinkService(WechatAppTokenService wechatAppTokenService) {
        super(wechatAppTokenService);
    }

    /**
     * Generate url link url link response.
     *
     * @param body the body
     * @return the url link response
     */
    public UrlLinkResponse generateUrlLink(UrlLinkBody body) {
        URI uri = UriComponentsBuilder.fromHttpUrl(ENDPOINT)
                .build()
                .toUri();
        ResponseEntity<UrlLinkResponse> response = this.client(body.getAppId())
                .postForEntity(uri, body, UrlLinkResponse.class);
        return response.getBody();
    }

}
